package com.rraj.common.mq.test.messagelistener;

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import com.xiaoleilu.hutool.date.DateUtil;
import org.springframework.stereotype.Component;

/**
 * Created by WangSheng on 2017/6/5.
 * 事务消费
 *
 * @author WangSheng
 */
@Component
public class MessageListenerImpl2 implements MessageListener {
    @Override
    public Action consume(Message message, ConsumeContext consumeContext) {
        try {
            System.out.println(DateUtil.now() + " 收到事务消费消息, Topic is:" +
                message.getTopic() + ", MsgId is:" + message.getMsgID() + ",message body:" + new String(
                message.getBody(), "UTF-8"));
        } catch (Exception e) {
            return Action.ReconsumeLater;
        }
        //如果想测试消息重投的功能,可以将Action.CommitMessage 替换成Action.ReconsumeLater
        return Action.CommitMessage;
    }
}
